<?php
/*************************************************
 * file description
 * @filename:           TeacherInfoModel.class.php
 * @desc:               教师信息表
 * @tables:             [dd_Teacher_info]
 * @date:               2016-9-25
 * @author:             大业
 * @version:            v1.0
 *************************************************/
namespace Common\Model;

use Common\Model\BaseModel;

class TeacherInfoModel extends BaseModel
{

	/**
	 * [获取表[Teacher_info]的信息]
	 * @method getInfo
	 * @author 大业
	 * @create 2016-09-27
	 * @param  [string] $condtion [查询条件]
	 * @return [array] [查询信息]
	 */
	public function getInfo($condtion,$pageSet)
	{
        $where = $condtion;
        $field = array(
			'id',				//自增ID
			'sch_id', 			//学校ID
			'tea_number', 		//教师编号(职工号)
			'tea_name', 		//教师姓名
			'tea_sex',  		//教师性别：1-男,2-女,0-其他
			'tea_identity_number',//教师身份证
			'tea_mobile',		//教师手机号
			'tea_phone',		//联系电话
			'tea_mail',			//电子邮箱
			'tea_weixin',		//教师微信号
			'tea_native_place',	//籍贯
			'tea_working_timed',//工作年限
			'tea_weixin',		//教师微信号
			'tea_duty',			//教师职务id
			'tea_certificate',	//荣誉证书
			'tea_introduction', //个人简介
			'tea_join_time',  	//入职时间
			'is_working', 		//是否在职(0-否(离职),1-是(在职)
			'is_charge', 		//是否为班主任(0-否,1-是)
			'created', 		//添加时间
        );

        $order = 'id desc';
        return $this->selectData($where,$field,$order,$pageSet);
	}


	/**
	 * [根据传入条件查询教师信息]
	 * @method showInfo
	 * @author 大业
	 * @create 2016-09-27
	 * @param  [int] id [教师id]
	 * @param  [string] $search [搜索信息]
	 * @param  [string] $style [输出样式控制标识:home/admin]
	 * @return [array] [输出信息]
	 */
	public function showInfo($id=null,$search,$style='home')
	{
		//查询条件(传入参数为空时,取所有未删除的数据)
		$where = '1 = 1 ';
		//教师id
		if(!empty($id)){
			$where = $where.' and id='.$id;
		}
		//查询条件
		if(!empty($search)){
			$where = $where.' and '.$search;
		}
		//取表数据
		$pageSet['limit'] = 20;
		$Info = $this->getInfo($where,$pageSet);

		//将显示的信息进行转换并输出
		$List = $this->fmtInfo($Info['list'],$style);
		return array('list'=>$List,'page'=>$Info['page']);
	}


	/**
	 * [格式化输出信息]
	 * @method fmtInfo
	 * @author 大业
	 * @create 2016-08-17
	 * @param  [array] $info [要格式的信息]
	 * @param  [string] $style [常用:common,后台:admin,前台:home(默认)]
	 * @return [array] [返回信息]
	 */
	private function fmtInfo($info,$style)
	{
		if(empty($info)){return null;}
		//常用数据
		if($style == 'common'){
			foreach ($info as $key => $value) {
				$List[$key]['id'] 		= $value['id'];
				$List[$key]['number'] 	= $value['tea_number'];
				$List[$key]['name'] 	= $value['tea_name'];
				$List[$key]['is_charge'] 	= $value['is_charge'];
			}
		//后台取数
		}else if($style == 'admin'){
			$List=$info;
			foreach ($info as $key => $value) {
				//$List[$key]['stu_patriarch']= $this->getPatriarchInfo($value['stu_patriarch_id']);
			}

		//前台取数 (前台出去的数据稍微转换下，以防暴露数据库字段)
		}else{
			foreach ($info as $key => $value) {
				$List[$key]['id'] 			= $value['id'];
				$List[$key]['number'] 		= $value['tea_number'];
				$List[$key]['name'] 		= $value['tea_name'];
				$List[$key]['sex'] 			= $value['tea_sex'];
				$List[$key]['native_place'] = $value['tea_native_place'];
				//其它后续再补充
			}
		}
		return $List;
	}

	/**
	 * [统计表数据信息]
	 * @method getCountNum
	 * @author 大业
	 * @create 2016-09-27
	 * @param  [string] $condition [传入条件]
	 * @return [arrayh] [返回统计信息]
	 */
	public function getCountNum($condition)
 	{
 		if(empty($condition)){
 			$condition='1 = 1';
 		}
 		$where = $condition;
 		$cntNum['all'] = $this->countData($where);
 		//总人数包括,在校和离校的，后续再分开处理.
 		// $where = $condition.' and is_del != 1 and is_pass != 0';
 		// $cntNum['use'] = $this->countData($where);
 		// $where = $condition.' and is_del != 1 and is_pass = 0';
 		// $cntNum['unuse']=$this->countData($where);
 		return $cntNum['all'];
 	}


	/**
	 * [根据教师id取教师姓名]
	 * @method getNameByID
	 * @auther 大业
	 * @create 2016-10-05
	 * @param  [int] $teaID [教师ID]
	 * @return [array] [教师姓名和管理标识]
	 */
	public function getNameByID($teaID)
	{
		if(empty($teaID)){
			return null;
		}
		if(strpos($teaID,',')){
			$where = 'id in ('.$teaID.')';
		}else{
			$where = 'id = '.$teaID;
		}
		$field = 'tea_name name,is_charge charge';
		$info = $this->selectData($where,$field);
		//dump($info);
		return $info;
	}



}
